# -*- coding: utf-8 -*-
import asyncio
import pickle
import sys

import pygame

from data.level_data import LevelData,load_data
from data.table_init import init_all_tables, init_data, generate_relationships
from scenes.colleague_talk import ColleagueTalkScene
from scenes.game_over_scene import GameOverScene

from scenes.office_scene import OfficeScene
from scenes.scene_manager import SceneManager
from scenes.start_scene import StartScene
from scenes.start_select_character_scene import StartSelectCharacterScene
from scenes.close_level import CloseLevelScene
from shared_variables import SCREEN
from utils import utils

if __name__ == '__main__':
    # 创建场景管理器并添加场景
    scene_manager = SceneManager()
    init_all_tables()
    init_data()
    generate_relationships()
    level_data = load_data()
    scene_manager.add_scene("start", StartScene(SCREEN))
    scene_manager.add_scene("start_select_character", StartSelectCharacterScene(screen=SCREEN, level_data=level_data))
    scene_manager.add_scene("office_scene", OfficeScene(screen=SCREEN, level_data=level_data))
    scene_manager.add_scene("ai_talk", ColleagueTalkScene(screen=SCREEN, level_data=level_data))
    scene_manager.add_scene("settle_project", CloseLevelScene(screen=SCREEN, level_data=level_data))
    scene_manager.add_scene("game_over", GameOverScene(screen=SCREEN))
    # 设置当前场景为开始场景
    scene_manager.set_current_scene("start")

    # 游戏循环
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()

            scene_result = scene_manager.handle_events(event)
            if scene_result:
                print(scene_result)
                scene_manager.set_current_scene(scene_result)

        scene_manager.draw()
        scene_manager.update()

        pygame.display.flip()
